package com.lgj.core;

import com.alibaba.fastjson.JSONObject;
import org.springframework.security.core.context.SecurityContextHolder;

/**
 * @author: guangjie.liao
 * @since: 2024/3/29 00:04
 * @description: 获取当前登录用户信息
 */
public class UserHelper {

    public static LoginUser getUser(){
        Object obj = SecurityContextHolder.getContext().getAuthentication().getPrincipal();
        if (obj instanceof LoginUser){
            return (LoginUser) obj;
        }else{
            return JSONObject.parseObject(JSONObject.toJSON(obj).toString(),LoginUser.class);
        }
    }

}
